"""
Web
"""

import streamlit as st
import logging
from pathlib import Path

from ..core import setup_logging
from .pages.main_page import MainPage
from .pages.upload_page import UploadPage
from .pages.processing_page import ProcessingPage
from .pages.result_page import ResultPage
from .pages.settings_page import SettingsPage

# 
st.set_page_config(
    page_title="",
    page_icon="",
    layout="wide",
    initial_sidebar_state="expanded"
)

class WebApp:
    """Web"""
    
    def __init__(self):
        # 
        setup_logging('INFO')
        self.logger = logging.getLogger(__name__)
        
        # session state
        self._init_session_state()
        
        # 
        self.pages = {
            "main": MainPage(),
            "upload": UploadPage(),
            "processing": ProcessingPage(),
            "result": ResultPage(),
            "settings": SettingsPage()
        }
    
    def _init_session_state(self):
        """session state"""
        if 'current_page' not in st.session_state:
            st.session_state.current_page = 'main'
        if 'processing' not in st.session_state:
            st.session_state.processing = False
        if 'result' not in st.session_state:
            st.session_state.result = None
        if 'video_info' not in st.session_state:
            st.session_state.video_info = None
        if 'settings' not in st.session_state:
            st.session_state.settings = {
                'whisper_model': 'base',
                'ollama_model': 'qwen2:7b',
                'language': 'auto',
                'summary_style': 'detailed',
                'output_formats': ['txt', 'srt', 'json']
            }
    
    def run(self):
        """Web"""
        # 
        current_page = st.session_state.current_page
        if current_page in self.pages:
            self.pages[current_page].render()
        else:
            st.error(f": {current_page}")
    
    def navigate_to(self, page_name: str):
        """"""
        if page_name in self.pages:
            st.session_state.current_page = page_name
            st.rerun()

def main():
    """"""
    app = WebApp()
    app.run()

if __name__ == "__main__":
    main()